<template>
  <div class="intelligence-graph-page">
    <div class="graph-content">
      <!-- 左侧筛选面板 -->
      <div class="filter-panel">
        <!-- 节点统计 -->
        <div class="statistics-section">
          <h3>节点统计</h3>
          <ul>
            <li>用户: {{ statistics.sourceCount }}个</li>
            <li>仓库: {{ statistics.intelligenceCount }}个</li>
            <li>文件: {{ statistics.assetCount }}个</li>
            <li>关键词: {{ statistics.cveCount }}个</li>
          </ul>
        </div>

        <!-- 图例 -->
        <div class="legend-section">
          <h3>图例</h3>
          <ul>
            <li>
              <span class="legend-icon user"></span>
              <span>用户</span>
            </li>
            <li>
              <span class="legend-icon repository"></span>
              <span>仓库</span>
            </li>
            <li>
              <span class="legend-icon file"></span>
              <span>文件</span>
            </li>
            <li>
              <span class="legend-icon keyword"></span>
              <span>关键词</span>
            </li>
          </ul>
        </div>
      </div>

      <!-- 中间图谱区域 -->
      <div class="graph-area">
        <div class="graph-toolbar">
          <el-input
            v-model="searchKeyword"
            placeholder="搜索节点..."
            @keyup.enter="searchNodes"
            class="search-input"
          >
            <template #append>
              <el-button @click="searchNodes"> 搜索 </el-button>
            </template>
          </el-input>

          <div class="graph-actions">
            <!-- <el-select
              v-model="currentLayout"
              @change="changeLayout"
              style="width: 120px; margin-right: 10px"
            >
              <el-option label="环形布局" value="circular" />
              <el-option label="力导向" value="force" />
            </el-select> -->

            <el-button @click="refreshGraph"> 刷新图谱 </el-button>
            <el-button @click="exportGraphPNG"> 导出图谱 </el-button>
            <!-- <el-button @click="autoLayout"> 自动布局 </el-button> -->
          </div>
        </div>

        <div class="graph-container">
          <div ref="graphChartRef" class="echarts-graph"></div>
        </div>

        <!-- 节点提示框 -->
        <div
          v-if="showTooltip"
          class="node-tooltip"
          :style="{
            left: tooltipPosition.left + 'px',
            top: tooltipPosition.top + 'px',
          }"
        >
          <div class="tooltip-title">{{ tooltipData.title }}</div>
          <div class="tooltip-content">
            <p v-for="(value, key) in tooltipData.content" :key="key">
              <span class="tooltip-key">{{ key }}:</span> {{ value }}
            </p>
          </div>
        </div>
      </div>

      <!-- 节点详情对话框 -->
      <DynamicDetailDialog
        v-model="detailVisible"
        title="节点详情"
        :groups="detailGroups"
        :loading="loadingDetail"
        width="800px"
      >
        <template #footer>
          <el-button @click="detailVisible = false">关闭</el-button>
          <el-button
            v-if="nodeDetail.url"
            type="primary"
            @click="viewFullDetail"
          >
            打开链接
          </el-button>
        </template>
      </DynamicDetailDialog>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted, nextTick, onUnmounted, computed } from "vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { useECharts } from "@pureadmin/utils";
import type { EChartsOption } from "echarts";
import type { Ref } from "vue";
import DynamicDetailDialog from "@/components/DynamicDetailDialog";
import type { DetailGroup } from "@/components/DynamicDetailDialog/types";

// API调用
import {
  getUnifiedGraphQuery,
  getUnifiedNodeDetail,
  getUnifiedDomains,
} from "../../servers";

// 页面状态
const username = ref("张三");
const activeTab = ref("intelligence");
const loading = ref(false);
const loadingDetail = ref(false);
const detailVisible = ref(false);
const nodeDetail = ref<any>({});
const searchKeyword = ref("");
const currentLayout = ref("force");
const graphChartRef = ref<HTMLDivElement>();
let chartInstance: any = null;
const showTooltip = ref(false);
const tooltipData = ref({ title: "", content: {} });
const tooltipPosition = ref({ left: 0, top: 0 });

// 筛选条件
const filters = reactive({
  centerNode: {
    type: "department", // 中心节点类型
    value: "", // 中心节点值
  },
  domains: [] as string[], // 域列表: ["pan_leak", "github_leak", "vulnerability", "asset_risk", "disposal"]
  maxDepth: 2, // 最大深度
  timeRange: "30d", // 时间范围
  limit: 100, // 限制节点数量
});

// 域选项列表
const domainOptions = ref<
  Array<{ code: string; name: string; is_active: boolean }>
>([]);

// 筛选选项
const filterOptions = reactive({
  timeRanges: [
    { value: "7d", label: "最近7天" },
    { value: "30d", label: "最近30天" },
    { value: "90d", label: "最近90天" },
    { value: "all", label: "全部" },
  ],
  severityLevels: [
    { value: "critical", label: "严重", color: "#ff4d4f", enabled: true },
    { value: "high", label: "高危", color: "#faad14", enabled: true },
    { value: "medium", label: "中危", color: "#ffd666", enabled: true },
    { value: "low", label: "低危", color: "#52c41a", enabled: true },
  ],
  limitOptions: [
    { value: 50, label: "50个节点" },
    { value: 100, label: "100个节点" },
    { value: 200, label: "200个节点" },
    { value: 500, label: "500个节点" },
  ],
});

// 统计数据
const statistics = reactive({
  sourceCount: 0,
  intelligenceCount: 0,
  assetCount: 0,
  cveCount: 0,
});

// ECharts 图表实例
const { setOptions, getInstance, resize } = useECharts(
  graphChartRef as Ref<HTMLDivElement>
);

// 获取节点样式（根据实际接口返回的style）
const getNodeStyle = (node: any) => {
  // 如果节点已经有style，直接使用
  if (node.style) {
    return {
      shape: "rect",
      size: node.size || 30,
      color: node.style.fill || "#1890ff",
      borderColor: node.style.stroke || "#fff",
      fontColor: "#fff",
      fontSize: 12,
    };
  }

  // 否则根据类型设置默认样式（使用 [width, height] 数组）
  const styles: any = {
    user: {
      shape: "rect",
      size: [120, 60], // 宽度120，高度60
      color: "#1890ff",
      borderColor: "#fff",
      fontColor: "#fff",
      fontSize: 14,
    },
    repository: {
      shape: "rect",
      size: [140, 60], // 宽度140，高度60
      color: "#722ed1",
      borderColor: "#fff",
      fontColor: "#fff",
      fontSize: 12,
    },
    file: {
      shape: "rect",
      size: [100, 50], // 宽度100，高度50
      color: "#ff4d4f",
      borderColor: "#fff",
      fontColor: "#fff",
      fontSize: 11,
    },
    keyword: {
      shape: "rect",
      size: [80, 40], // 宽度80，高度40
      color: "#fa8c16",
      borderColor: "#fff",
      fontColor: "#fff",
      fontSize: 10,
    },
  };

  // 根据严重程度设置文件节点颜色
  if (node.type === "file" && node.metadata?.severity) {
    const severity = node.metadata.severity;
    if (severity === "critical") {
      styles.file.color = "#ff4d4f";
    } else if (severity === "high") {
      styles.file.color = "#faad14";
    } else if (severity === "medium") {
      styles.file.color = "#ffd666";
    } else {
      styles.file.color = "#52c41a";
    }
  }

  return styles[node.type] || styles.file;
};

// 获取边样式（根据实际接口返回的style）
const getEdgeStyle = (edge: any) => {
  // 如果边已经有style，直接使用
  if (edge.style) {
    return {
      color: edge.style.stroke || "#1890ff",
      width: 2,
      style: edge.style.lineDash ? "dashed" : "solid",
    };
  }

  // 否则根据类型设置默认样式
  const styles: any = {
    owns: {
      color: "#a0c5e8",
      width: 2,
      style: "solid",
    },
    contains: {
      color: "#b37feb",
      width: 2,
      style: "solid",
    },
    matches: {
      color: "#ffd591",
      width: 2,
      style: "dashed",
    },
  };

  return styles[edge.type] || styles.owns;
};

// 转换API数据为ECharts Graph格式
const transformGraphData = (apiData: any) => {
  if (!apiData) {
    return { nodes: [], links: [] };
  }

  const nodes = Array.isArray(apiData.nodes) ? apiData.nodes : [];
  const edges = Array.isArray(apiData.edges) ? apiData.edges : [];

  // 转换节点为ECharts格式
  const echartsNodes = nodes.map((node: any) => {
    const style = getNodeStyle(node);
    // 如果节点有size，使用节点的size；否则使用样式的size
    let size = style.size;
    if (node.size) {
      // 如果节点size是数字，转换为数组；如果已经是数组，直接使用
      size =
        typeof node.size === "number" ? [node.size * 2, node.size] : node.size;
    }
    // 确保size是数组格式 [width, height]
    if (typeof size === "number") {
      size = [size * 2, size];
    }

    return {
      id: node.id,
      name: node.label || node.id,
      symbolSize: size, // 使用数组 [width, height]
      symbol: "rect", // 使用矩形符号
      itemStyle: {
        color: style.color,
        borderColor: style.borderColor,
        borderWidth: node.style?.lineWidth || 2,
      },
      label: {
        show: true,
        position: "inside",
        color: style.fontColor,
        fontSize: style.fontSize,
        formatter: (params: any) => {
          const name = params.name || "";
          // 如果名称太长，换行显示
          if (name.length > 15) {
            return name.substring(0, 15) + "\n" + name.substring(15);
          }
          return name;
        },
      },
      category: node.type,
      value: Array.isArray(size) ? size[0] : size,
      nodeType: node.type,
      metadata: node.metadata || {},
      severity: node.metadata?.severity,
    };
  });

  // 转换边为ECharts格式
  const echartsLinks = edges.map((edge: any) => {
    const style = getEdgeStyle(edge);

    return {
      source: edge.source,
      target: edge.target,
      label: {
        show: false, // 隐藏边的标签
        formatter: edge.label || edge.type || "",
        fontSize: 12,
        color: "#666",
      },
      lineStyle: {
        color: style.color,
        width: style.width,
        type: style.style === "dashed" ? "dashed" : "solid",
      },
      edgeType: edge.type,
    };
  });

  return { nodes: echartsNodes, links: echartsLinks };
};

// 渲染ECharts图谱
const renderGraph = (nodes: any[], links: any[]) => {
  const option: EChartsOption = {
    tooltip: {
      show: true,
      formatter: (params: any) => {
        if (params.dataType === "node") {
          const node = params.data;
          let content = `<div style="font-weight: bold; margin-bottom: 5px;">${node.name}</div>`;
          if (node.nodeType === "user") {
            content += `<div>类型: 用户</div>`;
            content += `<div>${node.metadata?.type || ""}</div>`;
          } else if (node.nodeType === "repository") {
            content += `<div>类型: 仓库</div>`;
            if (node.metadata?.url) {
              content += `<div>${node.metadata.url}</div>`;
            }
          } else if (node.nodeType === "file") {
            content += `<div>类型: 文件</div>`;
            if (node.metadata?.path) {
              content += `<div>路径: ${node.metadata.path}</div>`;
            }
            if (node.metadata?.severity) {
              content += `<div>严重程度: ${node.metadata.severity}</div>`;
            }
          } else if (node.nodeType === "keyword") {
            content += `<div>类型: 关键词</div>`;
            if (node.metadata?.keyword) {
              content += `<div>关键词: ${node.metadata.keyword}</div>`;
            }
          }
          return content;
        }
        return params.data.label?.formatter || "";
      },
    },
    series: [
      {
        type: "graph",
        layout: currentLayout.value === "force" ? "force" : "circular",
        data: nodes,
        links: links,
        categories: [
          { name: "user", itemStyle: { color: "#1890ff" } },
          { name: "repository", itemStyle: { color: "#722ed1" } },
          { name: "file", itemStyle: { color: "#ff4d4f" } },
          { name: "keyword", itemStyle: { color: "#fa8c16" } },
        ],
        roam: true,
        label: {
          show: true,
          position: "inside",
          formatter: "{b}",
          fontSize: 12,
        },
        edgeLabel: {
          show: false, // 隐藏边的标签
          formatter: "{c}",
          fontSize: 12,
          color: "#666",
        },
        labelLayout: {
          hideOverlap: false,
        },
        emphasis: {
          focus: "adjacency",
          lineStyle: {
            width: 4,
          },
        },
        lineStyle: {
          curveness: 0.3,
        },
        force: {
          repulsion: 2000,
          gravity: 0.1,
          edgeLength: 150,
          layoutAnimation: true,
        },
        circular: {
          rotateLabel: true,
        },
      },
    ],
  };

  setOptions(option);
  chartInstance = getInstance();
  setupChartEvents(); // 设置事件监听
};

// 加载域列表
const loadDomains = async () => {
  try {
    const res = await getUnifiedDomains();
    if (res.code === 2000 && res.data?.domains) {
      domainOptions.value = res.data.domains;
      // 默认选中所有激活的域
      if (filters.domains.length === 0) {
        filters.domains = res.data.domains
          .filter((d: any) => d.is_active)
          .map((d: any) => d.code);
      }
    }
  } catch (error: any) {
    console.error("获取域列表失败:", error);
  }
};

// 加载图谱数据
const loadGraphData = async () => {
  try {
    loading.value = true;

    // 构建请求参数（根据统一查询接口格式）
    const params: any = {
      time_range: filters.timeRange,
      limit: filters.limit,
      max_depth: filters.maxDepth,
    };

    // 如果有中心节点，添加 center_node
    if (filters.centerNode.value) {
      params.center_node = {
        type: filters.centerNode.type,
        value: filters.centerNode.value,
      };
    }

    // 如果有选中的域，添加 domains
    if (filters.domains.length > 0) {
      params.domains = filters.domains;
    }

    const res = await getUnifiedGraphQuery(params);
    if (res.code === 2000) {
      const { nodes, links } = transformGraphData(res.data);

      // 更新统计数据（从接口响应中获取）
      if (res.data.statistics) {
        // 根据实际返回的统计数据更新
        statistics.sourceCount = res.data.statistics.total_nodes || 0;
        statistics.intelligenceCount = res.data.statistics.total_edges || 0;
        // 可以根据 domains_included 或其他字段来更新
        if (res.data.statistics.domains_included) {
          statistics.assetCount =
            res.data.statistics.domains_included.length || 0;
        }
        statistics.cveCount = res.data.statistics.query_time_ms || 0;
      }

      // 渲染图谱
      await nextTick();
      if (nodes.length > 0) {
        renderGraph(nodes, links);
      } else {
        ElMessage.warning("暂无数据");
      }
    }
  } catch (error: any) {
    ElMessage.error(error?.message || "获取图谱数据失败");
  } finally {
    loading.value = false;
  }
};

// 筛选选项和统计数据都在 getIntelligenceGraphData 接口中返回，不需要单独获取

// 节点点击事件（通过ECharts事件绑定）
const setupChartEvents = () => {
  if (!chartInstance) return;

  chartInstance.off("click");
  chartInstance.on("click", async (params: any) => {
    if (params.dataType === "node") {
      const node = params.data;
      try {
        loadingDetail.value = true;
        const res = await getUnifiedNodeDetail({
          node_id: node.id,
          node_type: node.nodeType,
        });

        if (res.code === 2000) {
          nodeDetail.value = res.data;
          detailVisible.value = true;
        }
      } catch (error: any) {
        ElMessage.error(error?.message || "获取节点详情失败");
      } finally {
        loadingDetail.value = false;
      }
    } else if (params.dataType === "edge") {
      const link = params.data;
      ElMessage.info(`关系: ${link.label?.formatter || link.edgeType}`);
    }
  });
};

// 搜索节点（通过设置中心节点实现）
const searchNodes = async () => {
  if (!searchKeyword.value.trim()) {
    ElMessage.warning("请输入搜索关键词");
    return;
  }

  // 根据搜索关键词设置中心节点
  // 这里可以根据实际需求调整，比如根据关键词类型判断节点类型
  filters.centerNode = {
    type: "department", // 默认类型，可以根据实际需求调整
    value: searchKeyword.value,
  };
  loadGraphData();
};

// 刷新图谱
const refreshGraph = () => {
  loadGraphData();
};

// 切换布局
const changeLayout = (layoutName: string) => {
  currentLayout.value = layoutName;
  loadGraphData(); // 重新加载数据以应用新布局
};

// 自动布局
const autoLayout = () => {
  if (chartInstance) {
    // ECharts会自动重新布局
    chartInstance.resize();
  }
};

// 导出图谱PNG
const exportGraphPNG = () => {
  if (chartInstance) {
    const url = chartInstance.getDataURL({
      type: "png",
      pixelRatio: 2,
      backgroundColor: "#fff",
    });
    const link = document.createElement("a");
    link.href = url;
    link.download = `intelligence_graph_${new Date().getTime()}.png`;
    document.body.appendChild(link);
    link.click();
    document.body.removeChild(link);
    ElMessage.success("图谱导出成功");
  }
};

// 导出JSON数据（使用当前图谱数据）
const exportGraphJSON = async () => {
  try {
    if (!chartInstance) {
      ElMessage.warning("暂无图谱数据");
      return;
    }

    const option = chartInstance.getOption();
    const nodes = option.series[0].data || [];
    const links = option.series[0].links || [];

    const exportData = {
      nodes: nodes.map((node: any) => ({
        id: node.id,
        label: node.name,
        type: node.nodeType,
        size: node.symbolSize,
        metadata: node.metadata,
      })),
      edges: links.map((link: any) => ({
        source: link.source,
        target: link.target,
        type: link.edgeType,
      })),
    };

    // 创建下载链接
    const blob = new Blob([JSON.stringify(exportData, null, 2)], {
      type: "application/json",
    });
    const url = URL.createObjectURL(blob);
    const a = document.createElement("a");
    a.href = url;
    a.download = `github_graph_${new Date().getTime()}.json`;
    document.body.appendChild(a);
    a.click();
    document.body.removeChild(a);
    URL.revokeObjectURL(url);

    ElMessage.success("JSON数据导出成功");
  } catch (error: any) {
    ElMessage.error(error?.message || "导出JSON数据失败");
  }
};

// 筛选相关方法
const handleFilterChange = () => {
  // 可以在这里添加防抖处理
};

const applyFilters = () => {
  loadGraphData();
};

const resetFilters = () => {
  filters.centerNode = {
    type: "department",
    value: "",
  };
  filters.domains = domainOptions.value
    .filter((d) => d.is_active)
    .map((d) => d.code);
  filters.maxDepth = 2;
  filters.timeRange = "30d";
  filters.limit = 100;
  searchKeyword.value = "";

  // 重新加载数据
  loadGraphData();
};

// 节点详情页操作
const viewFullDetail = () => {
  // 打开链接
  if (nodeDetail.value?.url) {
    window.open(nodeDetail.value.url, "_blank");
  } else {
    ElMessage.warning("暂无链接");
  }
};

// 详情分组数据（根据实际接口返回的数据结构）
// 接口返回: { leak_count: 1, url: "https://github.com/facebook/react-internal" }
const detailGroups = computed<DetailGroup[]>(() => {
  if (!nodeDetail.value || Object.keys(nodeDetail.value).length === 0) {
    return [];
  }

  const detail = nodeDetail.value;

  // 根据实际返回的数据结构显示
  return [
    {
      title: "基本信息",
      type: "normal" as const,
      items: [
        {
          key: "url",
          label: "地址",
          value: detail.url || "-",
          span: 2,
        },
        {
          key: "leak_count",
          label: "泄露数量",
          value: detail.leak_count ?? 0,
        },
      ],
    },
  ];
});

// 辅助方法：根据评分或严重程度获取标签类型
const getSeverityType = (scoreOrSeverity: number | string) => {
  if (typeof scoreOrSeverity === "number") {
    if (scoreOrSeverity >= 9.0) return "danger";
    if (scoreOrSeverity >= 7.0) return "warning";
    if (scoreOrSeverity >= 4.0) return "info";
    return "success";
  }
  // 字符串类型（如 "critical", "high", "medium", "low"）
  const severity = String(scoreOrSeverity).toLowerCase();
  if (severity === "critical" || severity === "high") return "danger";
  if (severity === "medium") return "warning";
  return "info";
};

// 辅助方法：根据风险评分获取标签类型
const getRiskType = (score: number) => {
  if (score >= 80) return "danger";
  if (score >= 60) return "warning";
  if (score >= 40) return "info";
  return "success";
};

// 初始化
onMounted(async () => {
  // 等待组件初始化完成
  await nextTick();
  // 先加载域列表
  await loadDomains();
  // 然后加载图谱数据
  await loadGraphData();
});

// 组件卸载时清理
onUnmounted(() => {
  if (chartInstance) {
    chartInstance.dispose();
  }
});

// 暴露 resizeChart 方法供父组件调用
const resizeChart = () => {
  if (chartInstance) {
    chartInstance.resize();
  }
};

defineExpose({
  resizeChart,
});
</script>

<style scoped lang="scss">
.intelligence-graph-page {
  padding: 20px;
  background-color: #f5f7fa;
  min-height: 100vh;
  box-sizing: border-box;
}

.navbar-card {
  margin-bottom: 20px;
  border-radius: 8px;

  .navbar-content {
    display: flex;
    justify-content: space-between;
    align-items: center;

    .page-title {
      font-size: 18px;
      font-weight: 600;
      margin: 0;
      color: #333;
    }

    .user-info {
      color: #666;
      font-size: 14px;
    }
  }
}

.tabs-container {
  margin-bottom: 20px;
  background-color: #fff;
  border-radius: 8px;
  padding: 10px 20px 0;
}

.graph-content {
  display: flex;
  gap: 20px;
  height: calc(100vh - 150px);
}

.filter-panel {
  width: 280px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow-y: auto;
}

.filter-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.filter-item {
  display: flex;
  flex-direction: column;
  gap: 8px;

  label {
    font-size: 14px;
    color: #666;
    font-weight: 500;
  }

  .el-select,
  .el-input {
    width: 100%;
  }
}

.filter-actions {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

.statistics-section,
.legend-section {
  background-color: #f9f9f9;
  border-radius: 6px;
  padding: 12px;

  h3 {
    font-size: 14px;
    color: #333;
    margin-bottom: 10px;
    font-weight: 500;
  }

  ul {
    list-style: none;
    padding: 0;
    margin: 0;

    li {
      font-size: 13px;
      color: #666;
      margin-bottom: 6px;
      display: flex;
      align-items: center;
      gap: 8px;
    }
  }
}

.legend-icon {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;

  &.user {
    background-color: #1890ff;
  }

  &.repository {
    background-color: #722ed1;
    border-radius: 2px;
  }

  &.file {
    background-color: #ff4d4f;
    border-radius: 2px;
  }

  &.keyword {
    background-color: #fa8c16;
    border-radius: 2px;
  }
}

.graph-area {
  flex: 1;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 800px;
  height: 0; // 配合 flex: 1 使用，确保容器有高度
}

.graph-toolbar {
  padding: 10px 16px;
  border-bottom: 1px solid #eee;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.search-input {
  width: 300px;
}

.graph-actions {
  display: flex;
  align-items: center;
  gap: 5px;
}

.graph-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-height: 800px;
  height: 0; // 配合 flex: 1 使用，确保容器有高度
}

.echarts-graph {
  width: 100%;
  height: 100%;
  min-height: 600px;
}

.node-tooltip {
  position: absolute;
  background-color: rgba(0, 0, 0, 0.8);
  color: #fff;
  padding: 8px 12px;
  border-radius: 4px;
  font-size: 12px;
  z-index: 1000;
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  max-width: 250px;

  .tooltip-title {
    font-weight: bold;
    margin-bottom: 5px;
    padding-bottom: 5px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.3);
  }

  .tooltip-content {
    p {
      margin: 3px 0;
      line-height: 1.4;

      .tooltip-key {
        color: #ccc;
        display: inline-block;
        width: 60px;
      }
    }
  }
}

.detail-panel {
  width: 400px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.detail-header {
  padding: 12px 16px;
  border-bottom: 1px solid #eee;
  display: flex;
  justify-content: space-between;
  align-items: center;

  h3 {
    margin: 0;
    font-size: 16px;
    color: #333;
  }

  .close-btn {
    color: #999;
  }
}

.detail-content {
  flex: 1;
  padding: 16px;
  overflow-y: auto;

  .detail-section {
    margin-top: 16px;

    h4 {
      font-size: 14px;
      color: #333;
      margin-bottom: 8px;
      font-weight: 500;
    }
  }

  .detail-actions {
    margin-top: 20px;
    display: flex;
    gap: 10px;
  }
}

.el-table {
  font-size: 12px;

  .el-table__cell {
    padding: 6px 0;
  }
}

.el-descriptions {
  margin-bottom: 16px;

  .el-descriptions__label {
    font-weight: 500;
  }
}

@media (max-width: 1600px) {
  .filter-panel {
    width: 240px;
  }

  .detail-panel {
    width: 350px;
  }

  .search-input {
    width: 220px;
  }
}
</style>
